from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


from tensorflow.contrib.learn.python.learn.datasets.mnist import read_data_sets


minist = read_data_sets("/Users/linqiliang/Tensorflow",one_hot=True)

import tensorflow as tf

x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10])+0.1)

y = tf.nn.softmax(tf.matmul(x,W) + b)
y_ = tf.placeholder(tf.float32,[None,10])
cross_entropy = -tf.reduce_sum(y_*tf.log(y))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)

for i in range(1000):
    batch_xs,batch_ys = minist.train.next_batch(100)
    sess.run(train_step,feed_dict={x: batch_xs,y_: batch_ys})


correct_prediction = tf.equal(tf.argmax(y,1),tf.argmax(y_,1))

accuacy = tf.reduce_mean(tf.cast(correct_prediction,'float'))

print(sess.run(accuacy,feed_dict= {x:minist.test.images,y_: minist.test.labels}))


